package cn.duxiaod;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@ConditionalOnClass(IdProperties.class)
@EnableConfigurationProperties(IdProperties.class)
@Configuration
@ConditionalOnProperty(prefix = IdProperties.PREFIX,value = "enabled",matchIfMissing = true)
public class IdGenerateAutoConfiguration {
    @Autowired
    private IdProperties properties;

    @Bean
    @ConditionalOnMissingBean(IdGenerateService.class)
    public IdGenerateService idGenerateService() {
        return  new IdGenerateService(properties.getDatacenterId(),properties.getDatacenterId());
    }
}
